<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" type="text/css" href="/build/css/css/font-awesome.min.css"/>
    <link rel="stylesheet" type="text/css" href="/css/my-style.css"/>
</head>
    <style>
        .layui-input-block {
            margin-left: 150px;
        }

        .layui-form-label {
            width: 110px;
        }
    </style>
<body>
<!-- 弹框content -->
<div id="modal-content1" style="padding:20px;">
    <form class="layui-form" action="">
        <div type=""hidden>
            <div class="layui-form-item" >
                <label class="layui-form-label">父级菜单Id</label>
                <div class="layui-input-block">
                    <input type="text" name="parentId" required lay-verify="required" placeholder="请输入菜单名称" autocomplete="off" class="layui-input"
                           th:value="${resource.getId()}">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">父级菜单<span
                    style="color: red">★</span>：</label>
            <div class="layui-input-block">
                <input type="text" name="parentName" required lay-verify="required" readonly="readonly" placeholder="请输入菜单名称" autocomplete="off" class="layui-input"
                       th:value="${resource.getResourceName()}" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">菜单名称<span
                    style="color: red">★</span>：</label>
            <div class="layui-input-block">
                <input type="text" name="resourceName" required lay-verify="required" placeholder="请输入菜单名称" autocomplete="off" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">菜单类型<span
                    style="color: red">★</span>：</label>
            <div class="layui-input-block">
                <select name="resourceType" lay-verify="required" id="resourceType">
                    <option value="M">菜单目录</option>
                    <option value="C">子菜单</option>
                    <option value="F">操作按钮</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">url<span
                    style="color: red">★</span>：</label>
            <div class="layui-input-block">
                <input type="text" name="url" required lay-verify="required"
                       placeholder="请输入url路径" autocomplete="off" class="layui-input" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">权限表达式<span
                    style="color: red">★</span>：</label>
            <div class="layui-input-block">
                <input type="text" name="perms" required lay-verify="required"
                       placeholder="请输入权限表达式" autocomplete="off" class="layui-input" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" name="resourceName">排序<span
                    style="color: red">★</span>：</label>
            <div class="layui-input-block">
                <input type="text" name="orderNum" required lay-verify="required" oninput="value=value.replace(/[^\d]/g,'')"
                       placeholder="请输入排序数字" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注:</label>
            <div class="layui-input-block">
                <textarea name="remark" placeholder="请输入内容" id="remark" class="layui-textarea" ></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>

    <script src="/plugins/layui/layui.all.js"></script>
    <script type="text/javascript" src="../../static/js/jquery.min.js" th:src="@{/js/jquery.min.js}"></script>
    <script>
        //请求父菜单
        $(function () {
            $.ajax({
                type: "GET",//请求方式
                url: "/system/resource/getParentResource",
                dataType: "json",
                success: function (result) {
                    for (var i = 0; i < result.length; i++) {
                        $("#parentName").append("<option value='"+result[i]['resourceName']+"'>" + result[i]['resourceName'] + "</option>");
                    }
                }
            });
        });
    </script>
<script>
    // 增加项目表单
    layui.use(['form', 'layedit', 'laydate', 'jquery'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        //常规用法
        laydate.render({
            elem: '#startDate'
        });
        laydate.render({
            elem: '#endDate'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');
        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 5) {
                    return '标题至少得5个字符啊';
                }
            }
            , pass: [/(.+){6,12}$/, '密码必须6到12位']
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });

        //监听指定开关
        form.on('switch(switchStatus)', function (data) {
            this.value = this.checked ? "0" : "1";
        });

        var $ = layui.$;
        //监听提交
        form.on('submit(formDemo)', function (data) {
            $.ajax({
                type: 'POST',
                url: "/system/resource/add" ,
                data: data.field,
                async:false,
                success: function (res) {
                    if (res.code == 0) {
                        parent.layer.msg("新增成功");
                        parent.layer.closeAll();
                        parent.window.location.reload();
                    } else {
                        layer.msg("增加失败" + res.msg);
                        return false;
                    }
                }
            });
        });
    });

</script>
</body>
</html>